package com.example.springboot.mapper;
import org.apache.ibatis.annotations.*;
import java.util.List;
import com.example.springboot.pojo.LocationRecord;
@Mapper
public interface LocationRecordMapper {
    @Insert("insert into location_record(number,location_id,user_id,type,time,create_time) values(#{number},#{locationId},#{userId},'已预约',#{time},now())")
    void create(LocationRecord locationRecord);
    @Delete("delete from location_record where id=#{id}")
    void delete(Integer id);
    @Select({
            "SELECT lr.id,lr.number,lr.time,lr.type,lr.create_time ,u.username AS username, u.user_phone AS userPhone,l.name AS  LocationName, l.photo AS LocationPhoto",
            "FROM location_record lr ",
            "LEFT JOIN user u ON lr.user_id = u.id " ,
            "LEFT JOIN location l ON lr.location_id = l.id "})
    List<LocationRecord> findAll();

    @Select({"SELECT lr.id,lr.number,lr.time,lr.type,lr.create_time,u.username AS username, u.user_phone AS userPhone, l.name AS  LocationName, l.photo AS LocationPhoto",
            "FROM location_record lr " ,
            "LEFT JOIN user u ON lr.user_id = u.id " ,
            "LEFT JOIN location l ON lr.location_id = l.id ",
            "WHERE lr.number LIKE CONCAT('%', #{number}, '%')"})
    List<LocationRecord> fingByNumber(String numeber);
    @Select({"SELECT lr.id,lr.number,lr.time,lr.type,lr.create_time,u.username AS username, u.user_phone AS userPhone, l.name AS  LocationName, l.photo AS LocationPhoto",
            "FROM location_record lr " ,
            "LEFT JOIN user u ON lr.user_id = u.id " ,
            "LEFT JOIN location l ON lr.location_id = l.id ",
            "WHERE lr.user_id=#{userId}"})
    List<LocationRecord> findByUserId(Integer userId);
    @Select({"SELECT lr.id,lr.number,lr.time,lr.type,lr.create_time,u.username AS username, u.user_phone AS userPhone, l.name AS  LocationName, l.photo AS LocationPhoto",
            "FROM location_record lr " ,
            "LEFT JOIN user u ON lr.user_id = u.id " ,
            "LEFT JOIN location l ON lr.location_id = l.id ",
            "WHERE lr.location_id=#{locationId}"})
    List<LocationRecord> findByLocationId(Integer locationId);
    @Update("update location_record set type='个人取消'where id=#{id}")
    void updateByUser(Integer id);

    @Update("update location_record set type='已完成' where id=#{id}")
    void update(Integer id);

    //系统取消预约
    @Update("update location_record set type='系统取消'where id=#{id}")
    void updateByAdmin(Integer id);


}
